<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<meta name="renderer" content="webkit|ie-comp|ie-stand">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
<!--[if lt IE 9]>
<script type="text/javascript" src="lib/html5shiv.js"></script>
<script type="text/javascript" src="lib/respond.min.js"></script>
<![endif]-->
<link rel="stylesheet" type="text/css" href="/static/h-ui/css/H-ui.min.css" />
<link rel="stylesheet" type="text/css" href="/static/h-ui.admin/css/H-ui.admin.css" />
<link rel="stylesheet" type="text/css" href="/static/lib/Hui-iconfont/1.0.8/iconfont.css" />
<link rel="stylesheet" type="text/css" href="/static/h-ui.admin/skin/default/skin.css" id="skin" />
<link rel="stylesheet" type="text/css" href="/static/h-ui.admin/css/style.css" />
<link href="/static/css/common.css" type="text/css" rel="stylesheet">
<link href="/static/css/index.css" type="text/css" rel="stylesheet">
<!--[if IE 6]>
<script type="text/javascript" src="lib/DD_belatedPNG_0.0.8a-min.js" ></script>
<script>DD_belatedPNG.fix('*');</script>
<![endif]-->
<title>添加老师 - H-ui.admin v3.1</title>
<meta name="keywords" content="H-ui.admin v3.1,H-ui网站后台模版,后台模版下载,后台管理系统模版,HTML后台模版下载">
<meta name="description" content="H-ui.admin v3.1，是一款由国人开发的轻量级扁平化网站后台模板，完全免费开源的网站后台管理系统模版，适合中小型CMS后台系统。">
</head>
<body>
<article class="page-container">
	<form class="form form-horizontal" id="form-admin-add">
		<div class="row cl">
			<label class="form-label col-xs-3 col-sm-2">分类名：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<span class="select-box" style="width:150px;">
					<select name="cate_id" id="cate_id" class="select">
					  {foreach $cates as $key=>$vo}
					  	<option value="{$vo.id}">&nbsp;{$vo.catename}&nbsp;</option>
					  {/foreach}
					</select>
				</span>
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-3 col-sm-2">老师姓名：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<input type="text" class="input-text" value="" placeholder="老师" id="teacher" name="teacher">
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-3 col-sm-2">简介：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<textarea id="intro" name="intro" cols="30" rows="5"></textarea>
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-3 col-sm-2">老师照片：</label>
			<div class="formControls col-xs-8 col-sm-9">
                <div style="position:relative;" id="drop_area"></div>
                <p style="color:#ccc;font-size:12px;">建议尺寸宽高:1:1</p>
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-3 col-sm-2">背景墙：</label>
			<div class="formControls col-xs-8 col-sm-9">
                <div style="position:relative;" id="background"></div>
                <p style="color:#ccc;font-size:12px;">建议尺寸宽高:750:500</p>
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-3 col-sm-2">年龄：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<input type="number" class="input-text" value="" placeholder="20" id="age" name="age">
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-3 col-sm-2">工作年龄：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<input type="number" class="input-text" value="" placeholder="3" id="workage" name="workage">
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-3 col-sm-2">来源：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<input type="text" class="input-text" value="" placeholder="RYT瑜伽联盟注册教师" id="from" name="from">
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-3 col-sm-2">星座：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<input type="text" class="input-text" value="" placeholder="双子座" id="zodiac" name="zodiac">
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-3 col-sm-2">教学风采：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<div class="img-box full">
					<section class=" img-section">
						<p class="up-p">作品图片：<span class="up-span">最多可以上传9张图片，马上上传</span></p>
						<div class="z_photo upimg-div clear">

							<section class="z_file fl">
								<img src="/static/img/a11.png" class="add-img">
								<input type="file" name="file" id="file" class="file" value="" accept="image/jpg,image/jpeg,image/png,image/bmp" multiple="">
							</section>
						</div>
					</section>
				</div>
		        <aside class="mask works-mask">
					<div class="mask-content">
						<p class="del-p">您确定要删除作品图片吗？</p>
						<p class="check-p"><span class="del-com wsdel-ok">确定</span><span class="wsdel-no">取消</span></p>
					</div>
				</aside>
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-3 col-sm-2">详情：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<script id="editorc" name="detail" type="text/plain" style="width:100%;height:400px;"></script>
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-3 col-sm-2">排序：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<input type="number" class="input-text" value="" placeholder="0" id="sort" name="sort">
			</div>
		</div>
		<!-- <div class="row cl">
			<label class="form-label col-xs-3 col-sm-2">推荐：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<label class="radio-inline">
					<input type="radio" id="emailwy1" name="flag" value="1" />
					<label for="emailwy1">推荐</label>
				</label>
			</div>
		</div> -->
		<div class="row cl">
			<div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
				<input id="submit" class="btn btn-primary radius" type="button" value="&nbsp;&nbsp;提交&nbsp;&nbsp;">
			</div>
		</div>
	</form>
</article>

<!--_footer 作为公共模版分离出去--> 
<script type="text/javascript" src="/static/lib/jquery/1.9.1/jquery.min.js"></script> 
<script type="text/javascript" src="/static/lib/layer/2.4/layer.js"></script>
<script type="text/javascript" src="/static/h-ui/js/H-ui.min.js"></script> 
<script type="text/javascript" src="/static/h-ui.admin/js/H-ui.admin.js"></script> <!--/_footer 作为公共模版分离出去-->

<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript" src="/static/lib/jquery.validation/1.14.0/jquery.validate.js"></script> 
<script type="text/javascript" src="/static/lib/jquery.validation/1.14.0/validate-methods.js"></script> 
<script type="text/javascript" src="/static/lib/jquery.validation/1.14.0/messages_zh.js"></script> 
<script type="text/javascript" src="/static/lib/ueditor/1.4.3/ueditor.config.js"></script>
<script type="text/javascript" src="/static/lib/ueditor/1.4.3/ueditor.all.min.js"> </script>
<script type="text/javascript" src="/static/lib/ueditor/1.4.3/lang/zh-cn/zh-cn.js"></script>
<script type="text/javascript" src="/static/js/upload.js"></script>
<script type="text/javascript">
var formDatas = new FormData();
var fileall = [];
var imgpz;
var background;
$(function(){
	var ue = UE.getEditor('editorc');
});
$(function() {
    var delParent;
    var defaults = {
        fileType: ["jpg", "png", "bmp", "jpeg"],
        fileSize: 1024 * 1024 * 10
    };
    $(".file").change(function() {
        var idFile = $(this).attr("id");
        var file = document.getElementById(idFile);
        var imgContainer = $(this).parents(".z_photo");
        var fileList = file.files;
        var input = $(this).parent();
        var imgArr = [];
        var numUp = imgContainer.find(".up-section").length;
        var totalNum = numUp + fileList.length;
        if (fileList.length > 9 || totalNum > 9) {
            alert("上传图片数目不可以超过9个，请重新选择");
        } else if (numUp < 9) {
            fileList = validateUp(fileList);
            for (var i = 0; i < fileList.length; i++) {
            	fileall.push(fileList[i]);
                var imgUrl = window.URL.createObjectURL(fileList[i]);
                imgArr.push(imgUrl);
                var $section = $("<section class='up-section fl loading'>");
                imgContainer.prepend($section);
                var $span = $("<span class='up-span'>");
                $span.appendTo($section);
                var $img0 = $("<img class='close-upimg'>").on("click", function(event) {
                    event.preventDefault();
                    event.stopPropagation();
                    $(".works-mask").show();
                    delParent = $(this).parent();
                });
                $img0.attr("src", "/static/img/a7.png").appendTo($section);
                var $img = $("<img class='up-img up-opcity'>");
                $img.attr("src", imgArr[i]);
                $img.appendTo($section);
                var $p = $("<p class='img-name-p'>");
                $p.html(fileList[i].name).appendTo($section);
                var $input = $("<input id='taglocation' name='taglocation' value='' type='hidden'>");
                $input.appendTo($section);
                var $input2 = $("<input id='tags' name='tags' value='' type='hidden'/>");
                $input2.appendTo($section);
            }
        }
        setTimeout(function() {
            $(".up-section").removeClass("loading");
            $(".up-img").removeClass("up-opcity");
        }, 450);
        numUp = imgContainer.find(".up-section").length;
        if (numUp >= 9) {
            $(this).parent().hide();
        }
        $(this).val("");
    });
    $(".z_photo").delegate(".close-upimg", "click", function() {
        $(".works-mask").show();
        delParent = $(this).parent();
    });
    $(".wsdel-ok").click(function() {
        $(".works-mask").hide();
        var numUp = delParent.siblings().length;
        fileall.splice(numUp-delParent.index()-1,1)
        if (numUp < 10) {
            delParent.parent().find(".z_file").show();
        }
        delParent.remove();
    });
    $(".wsdel-no").click(function() {
        $(".works-mask").hide();
    });
    function validateUp(files) {
        var arrFiles = [];
        for (var i = 0, file; file = files[i]; i++) {
            var newStr = file.name.split("").reverse().join("");
            if (newStr.split(".")[0] != null) {
                var type = newStr.split(".")[0].split("").reverse().join("");
                if (jQuery.inArray(type, defaults.fileType) > -1) {
                    if (file.size >= defaults.fileSize) {
                        alert(file.size);
                        alert('您这个"' + file.name + '"文件大小过大');
                    } else {
                        arrFiles.push(file);
                    }
                } else {
                    alert('您这个"' + file.name + '"上传类型不符合');
                }
            } else {
                alert('您这个"' + file.name + '"没有类型, 无法识别');
            }
        }
        return arrFiles;
    }
})

$("#submit").click(function() {
	layer.load(1, {
	  shade: [0.1,'#fff'] //0.1透明度的白色背景
	});
	var cate_id=$("#cate_id").val();
	var teacher=$("input[name=teacher]").val();
	var intro=$("#intro").val();
	var age=$("input[name=age]").val();
	var workage=$("input[name=workage]").val();
	var from=$("input[name=from]").val();
	var zodiac=$("input[name=zodiac]").val();
	var detail=UE.getEditor('editorc').getContent();
	var sort=$("input[name=sort]").val();
	for(var i = 0;i<fileall.length;i++){
         formDatas.append("imgs[]",fileall[i]);
    }
	$.ajax({
	    type: 'POST',
	    url: "{:url('uploadtmd')}",
		contentType:false,
	    processData: false,
		dataType:"json",
		mimeType:"multipart/form-data",
	    data: formDatas,
	    success: function(result){
	        if(result.code==200){
				$.ajax({
				    type: 'POST',
				    url: "{:url('teacher_add')}",
				    data: {cate_id:cate_id,teacher:teacher,intro:intro,age:age,workage:workage,from:from,zodiac:zodiac,sort:sort,photo:result.photo,imgs:result.imgs,background:background,detail:detail},
				    success: function(resdata){
				        if(resdata.code==200){
							layer.msg(resdata.msg,{icon:1,time:1000});
							setTimeout("parent.location.reload()",1000);
				        }else{
							layer.msg(resdata.msg,{icon:2,time:3000});
				        }
				    },
				    error: function(){
						layer.msg('数据保存失败',{icon:2,time:3000});
				    }
				})
	        }else{
				layer.msg('图片上传失败',{icon:2,time:3000});
	        }
	    },
	    error: function(){
			layer.msg('图片上传失败！',{icon:2,time:3000});
	    }
	})
})
// $(function(){
// 	$('.skin-minimal input').iCheck({
// 		checkboxClass: 'icheckbox-blue',
// 		radioClass: 'iradio-blue',
// 		increaseArea: '20%'
// 	});
	
// 	$("#form-admin-add").validate({
// 		rules:{
// 		},
// 		onkeyup:false,
// 		focusCleanup:true,
// 		success:"valid",
// 		submitHandler:function(form){
// 			for(var i = 0;i<fileall.length;i++){
// 		         formDatas.append("imgs[]",fileall[i]);
// 		    }
// 			$(form).ajaxSubmit({
// 				type: 'post',
// 				url: "{:url('teacher_add')}",
// 				data:{photo:imgpz},
// 				success: function(data){
// 					if(data.code==200){
// 						// $.ajax({
// 					 //        type: 'POST',
// 					 //        url: "{:url('uploadtmd')}",
//       //   					contentType:false,
// 					 //        processData: false,
//       //   					dataType:"json",
//       //   					mimeType:"multipart/form-data",
// 					 //        data: formDatas,
// 					 //        success: function(res){
// 					 //            if(res.code==200){
// 						// 			layer.msg(res.msg,{icon:1,time:1000});
// 						// 			setTimeout("parent.location.reload()",1000);
// 					 //            }else{
// 						// 			layer.msg(res.msg,{icon:2,time:3000});
// 					 //            }
// 					 //        },
// 					 //        error: function(){
// 						// 		layer.msg(res.msg,{icon:2,time:3000});
// 					 //        }
// 					 //    })
// 						// var index = parent.layer.getFrameIndex(window.name);
// 						// parent.location.reload();
// 						// parent.layer.close(index);
// 						layer.msg(data.msg,{icon:1,time:1000});
// 						setTimeout("parent.location.reload()",1000);
// 					}else{
// 						layer.msg(data.msg,{icon:2,time:3000});
// 					}

// 				},
//                 error: function(XmlHttpRequest, textStatus, errorThrown){
// 					var index = parent.layer.getFrameIndex(window.name);
// 					parent.layer.close(index);
// 				}
// 			});
// 		}
// 	});
// });
var dragImgUpload = new DragImgUpload("#drop_area",{
    callback:function (files) {
        //回调函数，可以传递给后台等等
        if(files[0].size<3145728){
	        var file = files[0];
	        // var formData = new FormData();
	        formDatas.append("file",file);
	        // $.ajax({
	        //       type: 'POST',
	        //       url: "{:url('qiniuupload')}",
	        //       data:formData,
	        //       contentType: false, /*不可缺*/
	        //       processData: false, /*不可缺*/
	        //       success: function(response){
	        //         if(response.code==200){
	        //           imgpz=response.data
	        //         }else{
	        //           alert(response.msg);
	        //         }
	        //       },
	        //       error: function(err){

	        //       }
	        // })
        }else{
        	alert('出错');
        	location.replace(location.href);
        }
    }
});
var dragImgUpload = new DragImgUpload("#background",{
    callback:function (files) {
        //回调函数，可以传递给后台等等
        if(files[0].size<3145728){
	        var filex = files[0];
	        var formData = new FormData();
	        formData.append("file",filex);
	        $.ajax({
	              type: 'POST',
	              url: "{:url('qiniuupload')}",
	              data:formData,
	              contentType: false, /*不可缺*/
	              processData: false, /*不可缺*/
	              success: function(response){
	                if(response.code==200){
	                  background=response.data
	                }else{
	                  alert(response.msg);
	                }
	              },
	              error: function(err){

	              }
	        })
        }else{
        	alert('出错');
        	location.replace(location.href);
        }
    }
});
</script> 
<!--/请在上方写此页面业务相关的脚本-->
</body>
</html>